<template>
  <div>
    <div class="sort-box">
      <span>销量排序：</span>
      <div class="sort">
        <input type="radio" v-model="sort" name="sort" value="0" />全部
        <input
          type="radio"
          v-model="sort"
          name="sort"
          value="1"
          @click="sorts1()"
        />降序
        <input
          type="radio"
          v-model="sort"
          name="sort"
          value="2"
          @click="sorts2()"
        />升序
      </div>
    </div>
    <el-tabs @tab-click="getRole">
      <el-tab-pane label="合伙人" v-if="istabpane"></el-tab-pane>
      <el-tab-pane label="大客户" v-if="istabpane"> </el-tab-pane>
      <el-table
        :data="Datas"
        border
        style="width: 100%"
        @row-click="showDialog($event)"
      >
        <el-table-column
          v-for="(item, index) in lists"
          :key="index"
          :prop="item.prop"
          border
          :label="item.name"
          width="calc(1000px / lists.length)"
          sortable="custom"
        >
        </el-table-column>
      </el-table>
    </el-tabs>
  </div>
</template>

<script>
import { Bus } from "../../Bus";
export default {
  data() {
    return {
      role: 0,
      sort: 0,
      lists: [],
      Datas: [],
      isshow: false,
      istabpane: true,
    };
  },
  mounted() {
    Bus.$on("tab-lists", (value) => {
      this.lists = value;
    });
    Bus.$on("tab-datas", (value) => {
      this.Datas = value;
      console.log(value);
    });
    Bus.$on("istabpane", (value) => {
      this.istabpane = value;
    });
  },

  methods: {
    showDialog(el) {
      this.isshow = !this.isshow;
      Bus.$emit("showecharts", this.isshow);
    },
    getRole(tab) {
      this.role = tab.index;
      Bus.$emit("role", this.role);
    },
    sorts1() {
      let temp, i;
      let arr = JSON.parse(JSON.stringify(this.Datas));
      for (i = 0; i < arr.length - 1; i++) {
        if (arr[i].sale) {
          if (arr[i].sale < arr[i + 1].sale) {
            temp = arr[i + 1];
            arr[i + 1] = arr[i];
            arr[i] = temp;
          }
        }
        if(arr[i].active_value){
          if (arr[i].active_value < arr[i + 1].active_value) {
            temp = arr[i + 1];
            arr[i + 1] = arr[i];
            arr[i] = temp;
          }
        }
      }
      this.$nextTick(() => {
        this.Datas = arr;
      });
    },
    sorts2() {
      let temp, i;
      let arr = JSON.parse(JSON.stringify(this.Datas));
      for (i = 0; i < arr.length - 1; i++) {
       if (arr[i].sale) {
          if (arr[i].sale > arr[i + 1].sale) {
            temp = arr[i + 1];
            arr[i + 1] = arr[i];
            arr[i] = temp;
          }
        }
        if(arr[i].active_value){
          if (arr[i].active_value > arr[i + 1].active_value) {
            temp = arr[i + 1];
            arr[i + 1] = arr[i];
            arr[i] = temp;
          }
        }
      }
      this.$nextTick(() => {
        this.Datas = arr;
      });
    },
  },
};
</script>

<style lang="less" scoped>
.sort-box {
  display: flex;
  margin: 30px;
}
.el-tabs {
  margin-left: 10px;
  margin-right: 10px;
}
.list-box,
.data-box {
  width: 100%;
  display: flex;
}
.list-item,
.province-data,
.sales-data {
  width: 50%;
  height: 50px;
  line-height: 50px;
  border: 1px solid#000;
}
</style>